function [Qhat] = csg(A)
 
    [row,col]= size(A);
    Qhat = zeros(row,col);
    Rhat = zeros(1,col);
    
    Qhat(:,1)=A(:,1); 
    column1 = A(:,1);
    Rhat(1) = norm(column1);
    
    for j = 2 : col
        for i = 1: j-1            
            q(:,i) = ((Qhat(:,i)' * A(:,j))/(Qhat(:,i)' * Qhat(:,i)));
            r(:,j)= q(:,i) * Qhat(:,i);
            A(:,j)= A(:,j) -r(:,j);          
        end
        Qhat(:,j)=A(:,j);    
        Rhat(j)=norm(Qhat(:,j));
    end
    % Qhat = Qhat(:, all(Qhat));
    % 删除接近零的列
    tolerance = 1e-4; % 设置一个容忍的阈值，根据需要调整
    norms = sqrt(sum(Qhat.^2));
    nonzero_columns = norms > tolerance;
    Qhat = Qhat(:, nonzero_columns);